<?php

namespace app\api\controller;

use app\api\model\EnrollModel;
use app\api\validate\UserValidate;
use app\BaseController;
use think\Request;

class Enroll extends BaseController
{
    public function index(Request $request)
    {
        $data = $request->param();
        $validate = $validate = new UserValidate();
        $list = $validate->scene('enroll')->check($data);
        if (!$list) {
            return error($validate->getError());
        }
        //加密
        $str = createRandStr();
        $data['salt'] = $str;
        $data['password'] = md5($data['password'].$str);

        //入库
        $res = EnrollModel::create($data);
        if ($res) {
            return success('注册成功');
        }else{
            return error('注册失败');
        }
    }
}